package com.cc.controller;


import com.cc.service.FileService;
import com.cc.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 文件表 前端控制器
 * </p>
 *
 * @author CHENCHEN
 * @since 2023-03-21
 */
@Slf4j
@RestController
public class UploadController {

    @Autowired
    private FileService fileService;

    @GetMapping("background-slices")
    public CommonResponse<String> backgroundSlices(@RequestParam("file") MultipartFile file) throws Exception {
        return CommonResponse.SUCCESS(fileService.convertMultiFileBySlices(file));
    }

    @GetMapping("web-slices-one-by-one")
    public CommonResponse<String> webSlicesOneByOne(@RequestParam("file") MultipartFile file, String fileMd5, Integer sliceNo, Integer totalSliceNo) throws Exception {
        return CommonResponse.SUCCESS(fileService.uploadFileBySlices(file, sliceNo, totalSliceNo, fileMd5));
    }

    @GetMapping("web-slices-all")
    public CommonResponse<String> webSlicesAll(@RequestParam("files") MultipartFile files[], String fileMd5) throws Exception {
        return CommonResponse.SUCCESS(fileService.uploadFileBySlices(files, fileMd5));
    }

    @GetMapping("del-path")
    public void delPath(String filePath) throws Exception {
        fileService.deleteFilePath(filePath);
    }
}

